 $(function() {
     //密码显示与隐藏
     var count = 1;
     $('#eye').click(function() {
             //奇数次点击 显示
             if (count % 2 == 1) {
                 $('#pwd').attr('type', 'text');
                 $('#eye').attr('class', 'fa fa-eye');
             }
             //偶数次点击 隐藏
             else {
                 $('#eye').attr('class', 'fa fa-eye-slash');
                 $('#pwd').attr('type', 'password');
             }
             count++;
         })
         //enter键登录
     $(document).keydown(function() {
         if (event.keyCode == 13) { //回车键的键值为13
             $('button').trigger('click');
             //  console.log(111);
         }
     })
     $('button').click(function() {
         var username = $("input").eq(0).val();
         var password = $("input").eq(1).val();
         var obj = {
             username: username,
             password: password
         };
         if (username && password) {
             //用户名密码非空
             //发送请求
             $.ajax({
                 url: baseURL + '/user/login',
                 type: 'POST',
                 data: JSON.stringify(obj),
                 "contentType": 'application/json',
                 success: function(data) {
                     console.log(data);
                     if (data.status == 200) {
                         var token = data.data.token;
                         if (token) {
                             //存储token,使其他页面获取
                             sessionStorage.setItem("token", token)
                                 //页面跳转
                             $(location).attr("href", "./firstPg.html");
                         }
                     } else {
                         alert(data.message)
                     }
                 }
             });
         } else {
             //用户名密码有空
             alert("用户名或者密码不能为空!")
         }
     });
 });